package vd.cloud.com.dto;

import javax.persistence.Entity;
import java.text.DecimalFormat;
import java.util.Calendar;

/**
 * Created by VIET on 1/16/2015.
 */
@Entity
public class KidDTO {
    private String name;
    private String age;
    private Calendar birthDay;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public Calendar getBirthDay() {
        return birthDay;
    }

    public void setBirthDay(Calendar birthDay) {
        this.birthDay = birthDay;
        // set age
        if(this.birthDay != null){
            long year = birthDay.getTimeInMillis();
            long currentYear = Calendar.getInstance().getTimeInMillis();
            String pattern = "###.#";
            DecimalFormat decimalFormat = new DecimalFormat(pattern);
            // calculate age of person
            this.age = decimalFormat.format((currentYear - year)/ (365*24*60*60*1000));
        }
    }
}
